package com.ruyuan.payment.pay.controller.admin;

import com.ruyuan.payment.server.req.OrderPayQueryReq;
import com.ruyuan.payment.server.resp.CommonResp;
import com.ruyuan.payment.server.resp.OrderPayQueryResp;
import com.ruyuan.payment.server.resp.PageResp;
import com.ruyuan.payment.server.service.OrderPayService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.math.BigDecimal;

@RestController
@RequestMapping("/admin/order-pay")
public class AdminOrderPayController {

    @Resource
    private OrderPayService orderPayService;

    @GetMapping("/query-list")
    public CommonResp queryList(@Valid OrderPayQueryReq req) {
        CommonResp<PageResp<OrderPayQueryResp>> commonResp = new CommonResp<>();
        PageResp<OrderPayQueryResp> list = orderPayService.queryList(req);
        commonResp.setContent(list);
        return commonResp;
    }

    @GetMapping("/query-channel/{payNo}")
    public CommonResp queryChannel(@PathVariable String payNo) {
        CommonResp<String> commonResp = new CommonResp<>();
        String message = orderPayService.queryChannel(payNo);
        commonResp.setContent(message);
        return commonResp;
    }

    @GetMapping("/close-channel/{payNo}")
    public CommonResp closeChannel(@PathVariable String payNo) {
        CommonResp<String> commonResp = new CommonResp<>();
        String message = orderPayService.closeChannel(payNo);
        commonResp.setContent(message);
        return commonResp;
    }

    @GetMapping("/refund/{payNo}/{refundAmount}")
    public CommonResp refund(@PathVariable String payNo, @PathVariable BigDecimal refundAmount) {
        CommonResp<String> commonResp = new CommonResp<>();
        String message = orderPayService.refund(payNo, refundAmount);
        commonResp.setContent(message);
        return commonResp;
    }
}
